import datetime

from sqlalchemy import String, func
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.infrastructure.db.models.base import Base


class Country(Base):
    __tablename__ = "country"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(String(50), nullable=False)
    name_eng: Mapped[str] = mapped_column(String(50), nullable=False)
    servers = relationship("Server", back_populates="country")
    orders = relationship("Order", back_populates="country")
    created_at: Mapped[datetime.datetime] = mapped_column(server_default=func.now())

    def __str__(self):
        return self.name

    def __repr__(self):
        return f"<Country №{self.id} {self.name}>"
